public class User {
    String userName;
    String userPass;

    User(String userName, String userPass) {
        this.userName = userName;
        this.userPass = userPass;
    }

    public void Longin(){
        String userName = "Admin";
        String userPass = "123";
        if(!this.userName.equals(userName)){
            throw new UserNameException("用户名错误!");
        }
        if(!this.userPass.equals(userPass)){
            throw new UserPassException("用户密码错误!");
        }
        System.out.println("登录成功!");
    }


    public static void main(String[] args) {
        //自定义异常类
        //自定义异常类必须继承 Exception 或 Exception 的子类(Exception 默认是受查异常)

        try {
            User user = new User("Admin", "12");
            user.Longin();
        }catch(UserNameException e){
            e.printStackTrace();
        }catch(UserPassException e){
            System.out.println(".........");
            e.printStackTrace();
        }
        System.out.println("try 后的代码");
    }

    /*
     * .........
     * try 后的代码
     * UserPassException: 用户密码错误!
     * 	at User.Longin(User.java:17)
     * 	at User.main(User.java:26)
     *
     * 进程已结束，退出代码为 0
     */
}
